//
//  NetTool.m
//  SinaByOC
//
//  Created by 张锐 on 16/3/18.
//  Copyright © 2016年 zhangr. All rights reserved.
//

#import "NetTool.h"
#import <AFNetworking.h>
@implementation NetTool

+(void)networkingToolWithType:(NSString *)type andURLString:(NSString *)URLString andParameters:(NSDictionary *)parameters andSuccessBlock:(void(^)(id responseObject))successBlock{

    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain",nil];
    
    if ([type isEqualToString:@"get"]) {
    
        [manager GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            successBlock(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            NSLog(@"%@",error);
        }];
        
    }else if([type isEqualToString:@"post"]){
    
        [manager POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            successBlock(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"%@",error);
        }];
    
    }else{
        
        NSLog(@"请传入正确的type");
    
    }

}

@end
